/**
 * @Author George.
 * @Date 2018/9/4.
 * @Description: http 注入拦截.
 */

import Toast from "./Toast"

class Interceptor {
    constructor() {

    }
    request(config) {
            return config;
        }
        // Token_Error(10001, "登录过期，请您重新登录"),
    response(response) {
        return new Promise((resolve, reject) => {
                if (response.data.status < 5e2) {
                    resolve(response.data, "done")
                } else {
                    if (response.data.info) {
                        Toast.toast(response.data.info)
                        reject(response.data, "done")
                    }
                }
            })
            // 取消请求任务
    }

    responseError(error) {
        if (error.status == 401) {
            Toast.toast(error.data.msg)
        }
    }

    complete(result) {
        uni.hideNavigationBarLoading(); //完成停止加载
        uni.stopPullDownRefresh() //停止下拉刷新
    }
};
let Interceptor = Interceptor();
export {
    interceptor
}